/*
 *  ETEventListener.cpp
 *  EidoTron
 *
 *  Created by Luca Di Franco on 07/03/11.
 *  Copyright 2011 Luca Di Franco. All rights reserved.
 *
 */

#include "EidoTronApp.h"

#include "../Scene_organization/SceneNode.h"
#include "../Entities/Lightcycle.h"
#include "../Utilities/Timer.h"


void EidoTronApp::menuEventListener(SDL_Event* event)
{
	switch(event->type)
	{
		case SDL_QUIT:
			running = false;
			break;
		case SDL_KEYDOWN:
			switch (event->key.keysym.sym)
			{
				case SDLK_ESCAPE:
					running = false;
					break;
				case SDLK_p:
					pause = !pause;
					break;
				case SDLK_b:
					SceneNode::showCollisionSolids = !SceneNode::showCollisionSolids;
					render();
					break;
				default:
					break;
			}
			break;
		default:
			break;
	}
}

void EidoTronApp::gameEventListener()
{
	if ((pause) || (SceneNode::getPlayerNode() == NULL))
		return;
	Uint8* keystate = SDL_GetKeyState(NULL);
	if (keystate[SDLK_w])
		((Lightcycle*) SceneNode::getPlayerNode()->data)->accelerate(Timer::getLastLap());
	if (keystate[SDLK_a])
		SceneNode::getPlayerNode()->memRotate(((Lightcycle*) SceneNode::getPlayerNode()->data)->getAgility() * Timer::getLastLap(), 0.0f, 1.0f, 0.0f);
	if (keystate[SDLK_s])
		((Lightcycle*) SceneNode::getPlayerNode()->data)->decelerate(Timer::getLastLap());
	if (keystate[SDLK_d])
		SceneNode::getPlayerNode()->memRotate(-((Lightcycle*) SceneNode::getPlayerNode()->data)->getAgility() * Timer::getLastLap(), 0.0f, 1.0f, 0.0f);
}